package com.zego.wawaji.ui.bean.user;

import android.os.Parcel;
import android.os.Parcelable;

import com.zego.wawaji.base.config.AreaConfig;
import com.zego.wawaji.base.config.InfoConfig;
import com.zego.wawaji.base.data.BaseData;
import com.zego.wawaji.base.media.MediaMgr;

import org.json.JSONObject;

/**
 * 用户信息基类
 */
public class UserBasic extends BaseData implements Parcelable {
    public long uid;             // 用户Id
    private String avatar;       // 头像
    private String nickname;     // 昵称
    private String mobile;       // 个人资料手机号码

    // 地址
    private String province;      // 完整省份
    private String city;          // 完整城市
    private String provinceName;  // 展示省份
    private String cityName;      // 展示城市
    private int scity;            // 城市代码
    private int sprovince;        // 省份代码

    @Override
    public void parseJson(String s) {
        InfoConfig infoConfig = InfoConfig.getInstance();
        JSONObject detailObject = getJsonObject(s);
        this.setUid(detailObject.optLong("Id"));
        this.setAvatar(detailObject.optString("Avatar"));
        this.setNickname(detailObject.optString("NickName"));
        this.setMobile(detailObject.optString("Telphone"));
        int marry = detailObject.optInt("Marry");

        int pid = detailObject.optInt("Province");
        int cit = detailObject.optInt("City");
        this.setScity(cit);
        this.setSprovince(pid);
        this.setProvince(AreaConfig.getInstance().getProvinceByID(pid));
        this.setCity(AreaConfig.getInstance().getCityByID(cit));
        this.setProvinceName(AreaConfig.getInstance().getProvinceNameByID(pid));
        this.setCityName(AreaConfig.getInstance().getCityNameByID(cit));
    }

    // ------------ 工具方法 --------------

    /**
     * 获取简略省市拼接地址
     */
    public String getAddressShow() {
        String _province = (provinceName == null || "不限".equals(provinceName)) ? "" : provinceName;
        String _city = (cityName == null || "不限".equals(cityName)) ? "" : " " + cityName;
        return _province + _city;
    }

    /**
     * 获取省市拼接地址
     */
    public String getAddress() {
        String _province = (province == null || "不限".equals(province)) ? "" : province;
        String _city = (city == null || "不限".equals(city)) ? "" : " " + city;
        return _province + _city;
    }

    // ------------ Getter  Setter --------------

    public String getAvatar() {
        return avatar;  // 拼接头像地址
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public long getUid() {
        return uid;
    }

    public void setUid(long uid) {
        this.uid = uid;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public int getScity() {
        return scity;
    }

    public void setScity(int scity) {
        this.scity = scity;
    }

    public int getSprovince() {
        return sprovince;
    }

    public void setSprovince(int sprovince) {
        this.sprovince = sprovince;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.nickname);
        dest.writeLong(this.uid);
        dest.writeString(this.province);
        dest.writeString(this.city);
        dest.writeString(this.provinceName);
        dest.writeString(this.cityName);
        dest.writeInt(this.scity);
        dest.writeInt(this.sprovince);
        dest.writeString(this.mobile);
        dest.writeString(this.avatar);
    }

    public UserBasic() {
    }

    protected UserBasic(Parcel in) {
        this.nickname = in.readString();
        this.uid = in.readLong();
        this.province = in.readString();
        this.city = in.readString();
        this.provinceName = in.readString();
        this.cityName = in.readString();
        this.scity = in.readInt();
        this.sprovince = in.readInt();
        this.mobile = in.readString();
        this.avatar = in.readString();
    }
}
